import { checkDevice } from '@/utils/index'
import { shareLink, shareTitle, shareDesc, shareImg } from './weChatShare_conf'
/**
 *
 * @param { string } shareTitle 标题
 * @param { string } shareDesc 分享描述
 * @param { string } shareLink 分享回调地址
 * @param { string } shareImg  分享logo
 */
export function appShare(obj = {}) {
  var xPhone = checkDevice() //全局手机类型
  if ('IOS' == xPhone) {
    //ios大象新闻app环境
    if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.requestShareUrl) {
      window.webkit.messageHandlers.requestShareUrl.postMessage({
        articleId: process.env.VUE_APP_SCORE_ARTICLEID,
        title: obj.shareTitle || shareTitle,
        summary: obj.shareDesc || shareDesc,
        shareUrl: obj.shareLink || shareLink,
        image: obj.shareImg || shareImg
      })
    }
  } else {
    //Android大象新闻app环境
    if (window.Android && window.Android.tongYong) {
      window.Android.tongYong(
        'requestShareUrl',
        JSON.stringify({
          articleId: process.env.VUE_APP_SCORE_ARTICLEID,
          title: obj.shareTitle || shareTitle,
          summary: obj.shareDesc || shareDesc,
          shareUrl: obj.shareLink || shareLink,
          image: obj.shareImg || shareImg
        })
      )
    }
    return true
  }
}
